// HelloJNI.cpp
#include <jni.h>
#include <iostream>
#include <string>
#include "com_cande_jni_HelloWolrd.h"

JNIEXPORT void JNICALL Java_com_cande_jni_HelloWolrd_sayHello (JNIEnv *env, jobject obj, jobject person){


   // 获取 Person 类
    jclass personClass = env->GetObjectClass(person);

   // 获取 getName 方法 ID
    jmethodID getNameMethod = env->GetMethodID(personClass, "getName", "()Ljava/lang/String;");
    // 获取 getAge 方法 ID
    jmethodID getAgeMethod = env->GetMethodID(personClass, "getAge", "()I");

    // 调用 getName 方法
    jstring name = (jstring) env->CallObjectMethod(person, getNameMethod);
    // 调用 getAge 方法
    jint age = env->CallIntMethod(person, getAgeMethod);

    // 将 jstring 转换为 C++ string
    const char *nameChars = env->GetStringUTFChars(name, nullptr);
    std::string nameStr(nameChars);
    env->ReleaseStringUTFChars(name, nameChars);

    // 创建信息字符串
    std::string info = "Name: " + nameStr + ", Age: " + std::to_string(age);

    std::cout << info << std::endl;
}
